package filter

import (
	"adam2/internal/properties"
	"anubis-framework/pkg/io"
	"gorm.io/gorm"
)

// 过滤器：删除市盈率不满足要求的股票
type PeBetweenLimitFilter struct {
	db *gorm.DB
}

// 初始化
func (p *PeBetweenLimitFilter) Init(db *gorm.DB) {
	p.db = db
}

// 执行
func (p *PeBetweenLimitFilter) DoFilter(transactionDate string) {
	io.Infoln("过滤器：删除市盈率不满足要求的股票，交易日期[%s]", transactionDate)

	var peBetweenStart float64 = properties.QuantProperties_.PeBetweenStart
	var peBetweenEnd float64 = properties.QuantProperties_.PeBetweenEnd

	// 过滤器：删除PE不满足要求的股票
	p.db.Exec("delete quant_stock_filter t where t.pe < ? or t.pe > ?",
		peBetweenStart, peBetweenEnd)
}
